package pl.edu.agh;

import static pl.edu.agh.Values.maxPeople;

import java.util.ArrayList;
import java.util.Arrays;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

import pl.edu.agh.strategies.Random;
import pl.edu.agh.strategies.SameAsLastWeek;
import pl.edu.agh.strategies.WeekAverage;
import pl.edu.agh.strategies.WeekDayAverage;

public class ChartDemo extends ApplicationFrame {
	 /**
     * A demonstration application showing an XY series containing a null value.
     *
     * @param title  the frame title.
     */
    public ChartDemo(final String title, JFreeChart chart) {
        super(title);
        final ChartPanel chartPanel = new ChartPanel(chart);
        this.setDefaultCloseOperation(HIDE_ON_CLOSE);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

    }

  
    public static void main(final String[] args) {
    	ArrayList<Agent> agents = new ArrayList<Agent>();
		ArrayList<Integer> history = new ArrayList<Integer>();
		ArrayList<Class<? extends IStrategy>> strategies = new ArrayList<Class<? extends IStrategy>>();
		

		strategies.add(WeekDayAverage.class);
		
		for(int i=0;i<maxPeople/2;i++)
		{
			Agent bond = new Agent(history, strategies, HowCountStrategies.ALL);
			agents.add(bond);
		}
		strategies.add(0,Random.class);
		
		for(int i = maxPeople/2 + 1; i < maxPeople;i++)
		{
			Agent bond = new Agent(history, strategies, HowCountStrategies.ALL);
			agents.add(bond);
		}
		
		
		for(int i=0;i<70;i++)
		{
			System.out.println(MainLogic.step(agents, false));
			System.out.println(Arrays.toString(agents.get(0).getHistory().toArray()));
		}
		history = agents.get(0).getHistory();
    	ElFaroChartFactory factory = new ElFaroChartFactory();
        ChartDemo demo = new ChartDemo("XY Series Demo", factory.createChart(history));
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);

    }

}
